package trivia;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextPane;
import javax.swing.JButton;

public class FinishFrame {
	
	private JLabel jNameLabel = null;
	private JLabel jScoreLabel = null;
	private JTextPane jNameTextPane = null;
	private JTextPane jScoresTextPane = null;
	private JButton jExitButton = null;
	private JButton jPlayAgainButton = null;
	private JFrame jFinishFrame = null;  //  @jve:decl-index=0:visual-constraint="601,62"
	private JPanel jFFContentPane = null;
	
	
	public FinishFrame () {
		jFinishFrame = getJFinishFrame();
	}
	
	private JLabel getJNameLabel () {
		if (jNameLabel == null) {
			jNameLabel = new JLabel();
			jNameLabel.setText("Name: ");
			jNameLabel.setBounds(new Rectangle(30, 30, 75, 30));
		}
		return jNameLabel;
	}

	/**
	 * This method initializes jPointsLabel1	
	 * 	
	 * @return javax.swing.JLabel	
	 */
	private JLabel getJScoreLabel() {
		if (jScoreLabel == null) {
			jScoreLabel = new JLabel();
			jScoreLabel.setText("Scores: ");
			jScoreLabel.setBounds(new Rectangle(30, 74, 75, 30));
		}
		return jScoreLabel;
	}
	
	public void setScore (String score) {
		if(score.length() > 5)
			jScoresTextPane.setText(score.substring(0, 4)+"%");
		else
			jScoresTextPane.setText(score+"%");
		jScoresTextPane.setEditable(false);
	}
	/**
	 * This method initializes jNameTextPane	
	 * 	
	 * @return javax.swing.JTextPane	
	 */
	private JTextPane getJNameTextPane() {
		if (jNameTextPane == null) {
			jNameTextPane = new JTextPane();
			jNameTextPane.setBounds(new Rectangle(120, 29, 180, 30));
		}
		return jNameTextPane;
	}
	/**
	 * This method initializes jScoresTextPane	
	 * 	
	 * @return javax.swing.JTextPane	
	 */
	private JTextPane getJScoresTextPane() {
		if (jScoresTextPane == null) {
			jScoresTextPane = new JTextPane();
			jScoresTextPane.setBounds(new Rectangle(120, 75, 180, 30));
		}
		return jScoresTextPane;
	}
	/**
	 * This method initializes jExitButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	public JButton getJExitButton() {
		if (jExitButton == null) {
			jExitButton = new JButton();
			jExitButton.setText("Exit");
			jExitButton.setBounds(new Rectangle(180, 150, 150, 50));
			jExitButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					//TODO GUARDAR LOS PUNTAJES AL ARCHIVO
					
					System.exit(0);
				}
			});
		}
		return jExitButton;
	}
	/**
	 * This method initializes jPlayAgainButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJPlayAgainButton() {
		if (jPlayAgainButton == null) {
			jPlayAgainButton = new JButton();
			jPlayAgainButton.setText("Go back");
			jPlayAgainButton.setBounds(new Rectangle(15, 150, 150, 50));
			jPlayAgainButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					jFinishFrame.dispose();
				}
			});
		}
		return jPlayAgainButton;
	}

	public void setName (String name) {
		jNameTextPane.setText(name);
		jNameTextPane.setEditable(false);
	}
	
	public void setScores (int s) {
		
		String aux = Integer.toString(s);
		jScoresTextPane.setText(aux);
		jNameTextPane.setEditable(false);
		return;
	}

	/**
	 * This method initializes jFinishFrame	
	 * 	
	 * @return javax.swing.JFrame	
	 */
	public JFrame getJFinishFrame() {
		
			jFinishFrame = new JFrame();
			jFinishFrame.setSize(new Dimension (350, 258));
			jFinishFrame.setContentPane(getJFFContentPane());
			jFinishFrame.setTitle("Game over");
		
		return jFinishFrame;
	}

	/**
	 * This method initializes jFFContentPane	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJFFContentPane() {
		if (jFFContentPane == null) {
			jFFContentPane = new JPanel();
			jFFContentPane.setLayout(null);
			jFFContentPane.add(getJNameTextPane(), null);
			jFFContentPane.add(getJNameLabel(), null);
			jFFContentPane.add(getJScoreLabel(), null);
			jFFContentPane.add(getJScoresTextPane(), null);
			jFFContentPane.add(getJPlayAgainButton(), null);
			jFFContentPane.add(getJExitButton(), null);
		}
		return jFFContentPane;
	}
	
	public static void main (String [] args) {
		new FinishFrame();
		
	}
}
